<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>这是打印测试文件</title>
    <script src="./LodopFuncs.js"></script>
    <script src="./ceshi.js"></script>
    <script src="./vue.js"></script>
</head>

<body>
    <div id="app">
        <div class="content">
            <div class="header">
                <div class="button" style="background-color: #67C23A;" @click="setPrint">生成打印数据</div>
                <div class="button" style="background-color: #409EFF;" @click="printContent">打印一个(预览)</div>
                <div class="button" style="background-color: #409EFF;" @click="continuity">连续打</div>
            </div>
            <div style="width: 100%;height: auto;">
                <div style="width: 100%;height: auto;margin-bottom: 20px;" v-for="(item,index) in list" :key="index">
                    <table :id="'item'+index" style="width: 76mm;">
                        <tbody>
                            <tr>
                                <td colspan="2">
                                    <img src="./txm.png" alt="" style="width: 100%;">
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 70%;">
                                    <div style="display: flex;align-items: center;">
                                        <img src="./revice.png" alt="" style="width: 10mm;height: auto;">
                                        <div style="padding-left: 10px;flex: 1;text-align: left;line-height: 1.5;">
                                            <p style="font-size: 5mm;font-weight: bold;">{{item.name}}</p>
                                            <p style="font-size: 4mm;">136***12345</p>
                                            <p style="font-size: 3mm;color: #999999;">云南省昆明市官渡区高原明珠大酒店
                                            </p>
                                        </div>
                                    </div>
                                </td>
                                <td style="width: 30%;">
                                    <img src="./ewm.png" alt="" :style="{width: width*0.3-10 + 'mm', height: 'auto'}">
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <p style="text-align: left;">
                                        <span style="font-size: 6mm;color: #000000;font-weight: bold;">寄</span>
                                        <span style="font-size: 3mm;color: #999999;">代*兵 1*8926 云商省昆明市星贡区老拍市B栋3号</span>
                                    </p>
                                    <p style="text-align: left;font-size: 4mm;">托寄物:鲜花</p>
                                    <p style="text-align: left;font-size: 4mm;">备注:243</p>
                                    <p style="text-align: left;font-size: 4mm;">订单号:24090817272098458</p>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</body>
<script>
    let app = new Vue({
        el: '#app',
        data: {
            list: [],
            lodop: null,
            width: 104,
            height: 152,
            sheet: 1,
            timer: null,//定时器
        },
        mounted() {},
        methods: {
            setPrint() {
                this.list = [
                    {
                        name: '小猪佩奇'
                    },
                    {
                        name: '小羊苏西'
                    },
                    {
                        name: '大象艾米丽'
                    }
                ]
            },
            printContent() {
                let dome = document.getElementById('item1').innerHTML;
                let lodop = window.getLodop();
                if (!lodop) {
                    alert('请先安装打印控件');
                    return;
                }
                lodop.PRINT_INIT('测试打印');
                lodop.SET_PRINT_PAGESIZE(3, this.width + 'mm', this.height + 'mm', '');
                lodop.ADD_PRINT_HTM(0, 0, this.width + 'mm', this.height + 'mm', dome);
                //lodop.PREVIEW();
                lodop.PRINT();
                // lodop.PRINT_DESIGN();
                console.log(dome);
            },

            continuity() {
                if (this.length == 0) {
                    alert('暂无可以打印的数据');
                    return;
                }
                this.timer = setInterval(() => {
                    let lodop = null;
                    lodop = window.getLodop();
                    if (!lodop) {
                        alert('请先安装打印控件');
                        return;
                    }
                    let ye = 'item' + (this.sheet - 1);
                    let dome = document.getElementById(ye).innerHTML;
                    console.log('tt--t', dome)
                    lodop.PRINT_INIT('测试打印第' + this.sheet + '张');
                    lodop.SET_PRINT_PAGESIZE(3, this.width + 'mm', this.height + 'mm', '');
                    lodop.ADD_PRINT_HTM(0, 0, this.width + 'mm', this.height + 'mm', dome);
                    lodop.PRINT();
                    this.sheet++;
                    if (this.sheet > this.list.length) {
                        console.log('打印完成');
                        clearInterval(this.timer);
                        this.timer = null;
                    }
                }, 1000)
            }
        },
    })
</script>

<style>
    #app {
        width: 100%;
        height: auto;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .content {
        width: 76mm;
        height: auto;
    }

    .header {
        width: 100%;
        height: 60px;
        display: flex;
        align-items: center;
        gap: 0 10px;
    }

    .button {
        width: 100px;
        height: 40px;
        border-radius: 6px;
        text-align: center;
        line-height: 40px;
        font-size: 15px;
        color: #ffffff;
    }

    table thead td,
    table tfoot td {
        height: 0mm;
        border: none !important;
    }

    table {
        text-align: center;
        border-collapse: collapse;
        border: 0mm;
    }

    table tr,
    td {
        padding: 2mm;
        border: 0.5mm solid #000000;
    }

    table tr:last-child td {
        border: 0.5mm solid black;
    }

    p {
        padding: 0mm !important;
        margin: 0mm !important;
    }

</style>

</html>
